<template>
  <el-dialog
    append-to-body
    title="更新库存"
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    align="left"
    v-loading="currLoading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)"
    width="600px">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="库存:" align="left" prop="icon">
        <el-input-number v-model.number="form.nums" @change="checkNums" :min="0" :max="99999" style="width: 150px"></el-input-number>
        <div style="display: inline-block; margin-left: 20px">
          <span v-if="(this.form.nums-oldNums)>0" class="b green">+ {{ (this.form.nums-oldNums) }}</span>
          <span v-if="(this.form.nums-oldNums)<0" class="b red"> {{ (this.form.nums-oldNums) }}</span>
        </div>
      </el-form-item>
      <el-form-item label="更新备注:" align="left" prop="icon">
        <el-input v-model="form.info"  :maxlength="50" style="width: 200px"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'EditStockNumsDialog',
  components: {},
  props:{
    successFunction:Function
  },
  data: function () {
    return {
      dialogVisible: false,
      currLoading: false,
      oldNums:0,
      form: {
        productStockId:0,
        nums: 0,
        info: '',
      }
    }
  },
  mounted () {
  },
  methods: {
    checkNums:function () {
      this.form.nums=this.toInt(this.form.nums)
    },
    open: function (infoData) {
      this.form.productStockId=infoData.id
      this.form.nums=infoData.nums
      this.form.info=''
      this.oldNums=infoData.nums
      this.dialogVisible = true
      this.$forceUpdate()
    },
    submit: function () {
      let $this = this
      $this.currLoading = true
      var form=Object.assign({},$this.form)
      form.nums=form.nums-this.oldNums
      $this.MyRequest(this.ApiDoNameSupplier + 'Product/updateModelNums', form, function () {
        $this.$message.success('更新成功')
        $this.currLoading = false
        $this.form = {
          productStockId:0,
          nums: 0,
          info:''
        }
        $this.dialogVisible=false
        $this.$props.successFunction()
        $this.$forceUpdate()
      }, function () {
        $this.$message.success('操作失败，请重试')
        $this.currLoading = false
        $this.$forceUpdate()
      })
    }
  }
}
</script>

<style scoped>

</style>
